home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: Allan_Nienhuis@mindlink.bc.ca (Allan Nienhuis)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: returning an array from function
- Date: Sat, 06 Apr 1996 14:01:10 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4k5t9b$gvh@fountain.mindlink.net>
- References: <4jstd8$kh0@news1.sunbelt.net>
- NNTP-Posting-Host: line006.abb.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- bourne@infoave.net (Rick Huebner) wrote:
- [snip]
- >a pointer to the array, from a function. I have seen several examples of
- >returning a pointer, but it doesn't seem to work for me. My function is going
-
- you are probably returning a pointer to an array which will be out of
- scope when the function exits, and is therefore no longer valid. If
- you are creating the array in the function, use the new operator:
-
-
- char *String;
-
- String = new char[100];
-
- you can then return the pointer to String, and it will remain a valid
- array, then use delete[]String when you've finished using it outside
- of the function to free the memory used by the array. (this is very
- important)
-
-
-
- Allan_Nienhuis@Mindlink.bc.ca
-
-